//
//  ChildCell.m
//  IpadR
//
//  Created by edianzu on 2017/6/6.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "ChildCell.h"
#import "ChildModel.h"
@implementation ChildCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
 */
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
     if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
         [self cretUI];
     }
    
//     self.selectionStyle =UITableViewCellSelectionStyleNone;
     return self;
}

-(void)cretUI{
    
//    self.contentView.backgroundColor = [UIColor whiteColor];
    self.label = [[UILabel alloc]init];
    self.label.textColor = UIColorFromRGB(88, 88, 88);
    self.label.font = [UIFont boldSystemFontOfSize:17*AutoScaleHorizontal];
    [self.contentView addSubview:self.label];
    [self.label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView.mas_left).with.offset(50*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        
        make.size.mas_equalTo(CGSizeMake(80*AutoScaleHorizontal, 40*AutoScaleVertical));
    }];
    
    self.image = [[UIImageView alloc]init];
    [self.contentView addSubview:self.image];
    [self.image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).with.offset(-30*AutoScaleHorizontal);
        make.centerY.mas_equalTo(self.contentView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(20*AutoScaleHorizontal, 20*AutoScaleVertical));
    }];
}

-(void)reSetCell:(NSMutableDictionary *)dic andNum:(NSInteger)num{
    ChildModel * model = [dic objectForKey:@"ChildName"];
    self.label.text = model.ChildName;
 
    //四种状态四种图片  absence  allDone  halfDone noDone
    if (model.IsAbsense ) {
        self.image.image = [UIImage imageNamed:@"absence"];
        self.imageStatus = @"4";
    }else{
        int a  = 0;
        int b = 0;
        
        for (NSMutableArray * arr in [dic objectForKey:@"Project"]) {
            for (NSMutableDictionary * dict in arr) {
                if ([[dict objectForKey:@"proNum"]isEqualToString:@"1"]) {
                    if (model.Height !=nil) {
                        a= a+1;
                    }
                }
                if ([[dict objectForKey:@"proNum"]isEqualToString:@"2"]) {
                    if (model.Weight !=nil) {
                        a= a+1;
                    }
                }
                if ([[dict objectForKey:@"proNum"]isEqualToString:@"3"]) {
                    if ((model.IsMentalShuttleRun )||(model.IsMotorShuttleRun )||(model.ShuttleRun !=nil)) {
                        a= a+1;
                    }
                }
                if ([[dict objectForKey:@"proNum"]isEqualToString:@"4"]) {
                    if ((model.IsMentalSitReach )||(model.IsMotorSitReach )||(model.SitReach !=nil)) {
                        a= a+1;
                    }
                }
                if ([[dict objectForKey:@"proNum"]isEqualToString:@"5"]) {
                    if ((model.IsMentalBroadJump )||(model.IsMotorBroadJump )||(model.BroadJump !=nil)) {
                        a= a+1;
                    }
                }
                if ([[dict objectForKey:@"proNum"]isEqualToString:@"6"]) {
                    if ((model.IsMentalDoubleJump )||(model.IsMotorDoubleJump )||(model.DoubleJump !=nil)) {
                        a= a+1;
                    }
                }
                if ([[dict objectForKey:@"proNum"]isEqualToString:@"7"]) {
                    if ((model.IsMentalThrow )||(model.IsMotorThrow )||(model.Throw !=nil)) {
                        a= a+1;
                    }
                }
                if ([[dict objectForKey:@"proNum"]isEqualToString:@"8"]) {
                    if ((model.IsMentalBalance )||(model.IsMotorBalance )||(model.Balance !=nil)) {
                        a= a+1;
                    }
                }
                
                    b++;
            }
        }
//        NSLog(@"b======%d  a========%d",b,a);
        
        if (a ==0) {
           self.image.image = [UIImage imageNamed:@"noDone"];
           self.imageStatus = @"0";
        }
        if (a == b) {
           self.image.image = [UIImage imageNamed:@"allDone"];
            self.imageStatus = @"1";
        }
        if ((a!=0)&&(a<b)) {
            self.image.image = [UIImage imageNamed:@"halfDone"];
            self.imageStatus = @"2";
        }
    }
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
    // 这个判断selected，设置子试图状态
    if (selected) {
        self.contentView.backgroundColor = [HexColor colorWithHexString:@"#00bcab"];
        self.label.textColor = [UIColor whiteColor];
        if ([self.imageStatus isEqualToString: @"0"]) {
            self.image.image = [UIImage imageNamed:@"noDoneS"];
        }
        if ([self.imageStatus isEqualToString: @"1"]) {
            self.image.image = [UIImage imageNamed:@"allDoneS"];
        }
        if ([self.imageStatus isEqualToString: @"2"]) {
            self.image.image = [UIImage imageNamed:@"halfDoneS"];
        }
        if ([self.imageStatus isEqualToString: @"4"]) {
            self.image.image = [UIImage imageNamed:@"absence"];
        }
        
    }
    else {
        self.label.textColor = UIColorFromRGB(88, 88, 88);
        if ([self.imageStatus isEqualToString: @"0"]) {
            self.image.image = [UIImage imageNamed:@"noDone"];
        }
        if ([self.imageStatus isEqualToString: @"1"]) {
            self.image.image = [UIImage imageNamed:@"allDone"];
        }
        if ([self.imageStatus isEqualToString: @"2"]) {
            self.image.image = [UIImage imageNamed:@"halfDone"];
        }
        if ([self.imageStatus isEqualToString: @"4"]) {
            self.image.image = [UIImage imageNamed:@"absence"];
        }
    }
}

@end
